From 11144645fa69cdc5cd6e28c2e8fbff62efc7974a Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Sat, 29 Aug 2015 11:20:13 +0200 Subject: [PATCH] path: do not recurse into hidden/dot directories Cargo recursively looks for TOML manifest into child directories, sometimes getting into unrelated files when exploring hidden directories (eg. quilt .pc). This commit lets cargo skip dot directories, to partially avoid the issues described in #1423. Signed-off-by: Luca Bruno --- src/cargo/ops/cargo_read_manifest.rs | 5 +++-- src/cargo/sources/path.rs | 15 ++++++++++----- tests/test_cargo_compile.rs | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 123a92039..741445510 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -43,8 +43,9 @@ pub fn read_packages(path: &Path, source_id: &SourceId, config: &Config) try!(walk(path, &mut |dir| { trace!("looking for child package: {}", dir.display()); - // Don't recurse into git databases - if dir.file_name().and_then(|s| s.to_str()) == Some(".git") { + // Don't recurse into hidden/dot directories + let name = dir.file_name().and_then(|s| s.to_str()); + if name.map(|s| s.starts_with(".")) == Some(true) { return Ok(false) } diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 0e3668b42..0bca3de26 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -255,11 +255,16 @@ impl<'cfg> PathSource<'cfg> { } for dir in try!(fs::read_dir(path)) { let dir = try!(dir).path(); - match (is_root, dir.file_name().and_then(|s| s.to_str())) { - (_, Some(".git")) | - (true, Some("target")) | - (true, Some("Cargo.lock")) => continue, - _ => {} + let name = dir.file_name().and_then(|s| s.to_str()); + // Skip dotfile directories + if name.map(|s| s.starts_with(".")) == Some(true) { + continue + } else if is_root { + // Skip cargo artifacts + match name { + Some("target") | Some("Cargo.lock") => continue, + _ => {} + } } try!(PathSource::walk(&dir, ret, false, filter)); } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index ca147db34..62dfd76f2 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1828,6 +1828,24 @@ test!(ignore_dotfile { execs().with_status(0)); }); +test!(ignore_dotdirs { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/bin/a.rs", "fn main() {}") + .file(".git/Cargo.toml", "") + .file(".pc/dummy-fix.patch/Cargo.toml", ""); + p.build(); + + assert_that(p.cargo("build"), + execs().with_status(0)); +}); + + test!(custom_target_dir { let p = project("foo") .file("Cargo.toml", r#" -- 2.30.2